<template>
	<div class="admin-app">
		<div class="task-search">
			<div class="task-search_martio">
				<div class="task-search_text">应用中心</div>
				<div class="task-search_box">
					<i class="el-icon-search"></i>
					<el-input placeholder="请输入搜索内容" v-model="selectInput" @input="selectClick"></el-input>
				</div>
			</div>
		</div>
		<div class="admin-app-flex" v-if="viewModel.menus.length!=0">
			<div class="admin-app-list" v-for="(item, index) in viewModel.menus" :key="index" @click="linkTo(item)" :title="item.name" v-show="item.isEnable">
				<div class="admin-app-icon">
					<x-icon :xClass="item.icon" color="#fff" size="30"></x-icon>
				</div>
				<div class="admin-app-cont">
					<div class="admin-app-title">{{item.name}}</div>
					<div class="admin-app-intro">
						<span class="admin-app-span" v-for="(itemChild, indexChild) in item.menus" :key="index+indexChild" v-show="indexChild < 2">{{itemChild.name}}、</span>
					</div>
				</div>
			</div>
		</div>
		<zk-nodata v-else></zk-nodata>
	</div>
</template>

<script>
	import './var.scss'
	import ala from 'ala'
	export default {
		data() {
			return {
				viewModel: {
					menus: []
				},
				widgetModel: {},
				selectInput: '',
				selectModel: {}
			}
		},
		props: {
			widget: {}
		},
		mounted() {
			this.init()
		},
		methods: {
			async init() {
				var data = this.$ala.vuexLocalGet(ala.themeRoleCacheKey(), true)
				this.widgetModel = data
				for (let i of this.widgetModel.menus) {
					if (i.url === '/Admin/App') {
						this.viewModel = i
						this.selectModel = JSON.parse(JSON.stringify(i))
					}
				}
			},
			linkTo(data) {
				if (data.menus !== null) {
					data.asideWidth = '200px'
				} else {
					data.asideWidth = '92px'
				}
				this.$bus.$emit('global_bus_admin_app_click', this.widgetModel, data)
			},
			selectClick() {
				if (this.selectInput !== '') {
					var data = []
					this.selectModel.menus.forEach(element => {
						if (element.name.indexOf(this.selectInput) > -1) {
							data.push(element)
						}
					})
					this.viewModel.menus = data
				} else {
					this.viewModel = JSON.parse(JSON.stringify(this.selectModel))
				}
			}
		}
	}
</script>